{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geoscilabs.dcip.sphereElectrostatic_example import (\n",
    "    interact_conductiveSphere, interactive_two_configurations_comparison\n",
    ")\n",
    "from IPython.display import display\n",
    "from ipywidgets import *\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# **Conductive or Resistive Sphere in a wholespace with a constant, uniform electric field $E_0$**\n",
    "\n",
    "Parameters:\n",
    "\n",
    " - **Log_sig0** : log10 of the conductivity of the background (for example, a value of -5 means a conductivity of $10^{-5}$ S/m)\n",
    " \n",
    " - **Log_sig1** : log10 conductivity of the sphere\n",
    " \n",
    " - **$ R $**: radius of the sphere\n",
    "     \n",
    "The following example allows the user to plot any of the following physical values: \n",
    "\n",
    " - **Electric Potential** (**Total** or **Secondary**)\n",
    " \n",
    " - **Electric Field** (**Total** or **Secondary**)\n",
    " \n",
    " - **Current Density** (**Total** or **Secondary**)\n",
    " \n",
    " - **Charges density**\n",
    " \n",
    "To visualise configuration and primary potential, clic on \"Configuration\" (*Note that others buttons are then deactivated*)\n",
    "\n",
    "Buttons FigureX**a** allow to choose to plot either Total or Secondary Field.\n",
    "\n",
    "Buttons FigureX**b** allow to choose the physical value to plot.\n",
    "\n",
    "Please visit http://em.geosci.xyz/content/maxwell2_static/fields_from_grounded_sources_dcr/electrostatic_sphere.html for more information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ba403f185534431dba821c030ba95499",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=50.0, description='R', max=50.0, step=10.0), FloatSlider(value=-3.0, d…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function geoscilabs.dcip.sphereElectrostatic_example.interact_conductiveSphere(R, log_sig0, log_sig1, Figure1a, Figure1b, Figure2a, Figure2b)>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Function to visualise and compare any two plots for the same configuration\n",
    "    \n",
    "interact(interact_conductiveSphere,\n",
    "        R=FloatSlider(min=0., max =50., step=10., value=50.),\n",
    "        log_sig0=FloatSlider(min=-5., max =0., step=0.5,value=-3.),\n",
    "        log_sig1=FloatSlider(min=-5., max =0., step=0.5,value=-1.),\n",
    "        Figure1a=ToggleButtons(options=['Configuration','Total','Secondary'],value = 'Total'),\n",
    "        Figure1b=ToggleButtons(options=['Potential','ElectricField','CurrentDensity','ChargesDensity'],value = 'ElectricField'),\n",
    "        Figure2a=ToggleButtons(options=['Total','Secondary'],value = 'Secondary'),\n",
    "        Figure2b=ToggleButtons(options=['Potential','ElectricField','CurrentDensity','ChargesDensity'],value = 'ElectricField'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Building some intuition for DC problem"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In real life, we do not know the underground configuration. We only see the\n",
    "data (in DCIP survey, Potentials difference between two electrodes) and we are trying to model the underground based from them. \n",
    "\n",
    "**There are several set of parameters that can fit perfectly a given data set**. Even in the simple\n",
    "case presented here, where we know it is a sphere, and whose response can be calculated analytically, \n",
    "we can find several configuration that can produce the same data along the same profile."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This code allow to plot and compare two differents configurations responses to the same survey.\n",
    "\n",
    "- **Log_sig0**: background log10 conductivity for both configurations\n",
    "\n",
    "- **Log_sig1**: sphere log10 conductivity in configuration 0\n",
    "\n",
    "- **Log_sig2**: sphere log10 conductivity in configuration 1\n",
    "\n",
    "- **R0**: Sphere's radius in configuration 0\n",
    "\n",
    "- **R1**: Sphere's radius in configuration 1\n",
    "\n",
    "- **E0**: uniform E field value\n",
    "\n",
    "- **start**: start point for the profile start.shape = (2,)\n",
    "\n",
    "- **end**: end point for the profile end.shape = (2,)\n",
    "\n",
    "- **dipole_number**: number of dipoles\n",
    "\n",
    "- **electrode_spacing**: Space between the M and N electrodes\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### **Are you able to find two spheres whose outside potentials are the same?**\n",
    "\n",
    "(one solution with \"matching_spheres_example\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "acf80ef3317a466ab06e9696804927e4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=-3.0, description='log_sig0', max=0.0, min=-5.0, step=0.5), FloatSlide…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function geoscilabs.dcip.sphereElectrostatic_example.interactive_two_configurations_comparison(log_sig0, log_sig1, log_sig2, R0, R1, xstart, ystart, xend, yend, dipole_number, electrode_spacing, matching_spheres_example)>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Visualisation of the responses of two configurations to a (pseudo) DC resistivity survey\n",
    "interact(interactive_two_configurations_comparison,\n",
    "         R0=FloatSlider(min=0., max =50., step=10., value=50.),\n",
    "         R1=FloatSlider(min=0., max =50., step=10., value=50.),\n",
    "         log_sig0=FloatSlider(min=-5., max =0., step=0.5,value=-3.),\n",
    "         log_sig1=FloatSlider(min=-5., max =0., step=0.5,value=-5.),\n",
    "         log_sig2=FloatSlider(min=-5., max =0., step=0.5,value=-1.),\n",
    "         xstart = FloatSlider(min=-200., max =200., step=10.,value=-200.),\n",
    "         ystart = FloatSlider(min=-200., max =200., step=10.,value=100.),\n",
    "         xend = FloatSlider(min=-200., max =200., step=10.,value=200.),\n",
    "         yend = FloatSlider(min=-200., max =200., step=10.,value=100.),\n",
    "         dipole_number = IntSlider(min=1, max=40, step=10,value=22),\n",
    "         electrode_spacing = FloatSlider(min=0., max =100., step=5.,value=20.),\n",
    "         matching_spheres_example = ToggleButton())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "widgets": {
   "state": {
    "17ef604df6f34b91875cedb051f996e3": {
     "views": [
      {
       "cell_index": 2
      }
     ]
    },
    "8a8a311386e349b191248f5b8a7780ba": {
     "views": [
      {
       "cell_index": 7
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
